package com.example.core.config;

import com.example.util.str.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
public class GlobalConfig {

    //所有服务
    @Value("globalConfig.services")
    public static String[] services;
    //当前服务名称
    @Value("spring.application.name")
    public static String serverName;


    public static String[] getServices() {
        return services;
    }

    public  void setServices(String[] services) {
        GlobalConfig.services = services;
    }

    public static String getServerName() {
        return serverName;
    }

    public  void setServerName(String serverName) {
        GlobalConfig.serverName = serverName;
    }

    //验证服务是否合法
    public static boolean vaildaServer(String serverName){
        if(StringUtils.isEmpty(serverName)){
            return false;
        }
        return Arrays.asList(GlobalConfig.services).stream().anyMatch(x->x.equals(serverName));
    }





}
